package HASH;

import java.util.*;

public class item12 {
    public static String intToRoman(int num) {
        Map<Integer, String> map = new LinkedHashMap<>();
        map.put(1000,"M");
        map.put(900,"CM");
        map.put(500,"D");
        map.put(400,"CD");
        map.put(100,"C" );
        map.put(90,"XC");
        map.put(50,"L");
        map.put(40,"XL");
        map.put(10,"X");
        map.put(9,"IX");
        map.put(5, "V" );
        map.put(4,"IV");
        map.put( 1,"I");
        System.out.println(map);

        Set entries = map.entrySet();
        String str = "";
        int still = num;
        for(Object o:entries)
        {  Map.Entry entry = (Map.Entry) o;
            if(still/(int)(entry.getKey())!=0)
            {
                int count = still/(int)(entry.getKey());
                for (int i = 0; i < count; i++) {
                    str = str+entry.getValue();
                }
            }
            still = still%(int)(entry.getKey());
            if(still==0)
            {
                break;
            }
        }


        return str;
    }

    public static void main(String[] args) {
        int num = 287;
        String str = intToRoman(num);
        System.out.println(str);
    }
}
